#include <cstdio>

using namespace std;

typedef long long ll;
const int maxn=1000000, mods=1000000007;

ll fact[maxn+1], invf[maxn+1];

ll qpower(ll a, int n) {
    ll s=1;
    for (; n; n/=2) {
        if (n&1) s=s*a%mods;
        a=a*a%mods;
    }
    return s;
}

void initFact(int n) {
    fact[0] = 1;
    for (int i=1; i<=n; i++) fact[i] = fact[i-1]*i%mods;
    invf[n] = qpower(fact[n], mods-2);
    for (int i=n; i; i--) invf[i-1] = invf[i]*i%mods;
}

ll c(int m, int n) {return fact[m]*invf[n]%mods*invf[m-n]%mods;}

int main() {
    freopen("ball.in", "r", stdin);
    freopen("ball.out", "w", stdout);

    static int f[maxn+1], s[maxn+1], a[maxn+1], b[maxn+1];
    ll ans[maxn+1];
    int n;
    scanf("%d", &n);
    initFact(n);
    for (int i=2; i<=n; i++) scanf("%d", f+i);
    for (int i=1; i<=n; i++) {
        scanf("%d", a+i);
        ans[i] = 1;
    }
    bool flag = true;
    for (int i=n; flag && i>1; i--) {
        s[i]++;
        b[i] += a[i];
        flag = b[i]>=s[i];
        s[f[i]] += s[i];
        b[f[i]] += b[i];
        ans[f[i]] = ans[f[i]]*ans[i]%mods*c(s[f[i]], s[i])%mods*c(b[f[i]]-s[f[i]], b[i]-s[i])%mods;
    }

    printf("%lld\n", flag*ans[1]);

    fclose(stdin);
    fclose(stdout);
    return 0;
}
